﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Base;

namespace ConAppCore
{
    internal class TestTypeEx
    {
        public static void Test()
        {
            //string filePath = @"D:\SelfCode\UtilZ.DotnetDBEx\Test\ConAppCore\bin\Debug\net6.0\DBPlugins\DM\Debug\net6.0\DmProvider.dll";
            //AssemblyName assemblyName = AssemblyName.GetAssemblyName(filePath);
            //string name = AssemblyEx.GetAssemblyName(filePath);

            //Type type = typeof(TestTypeEx);
            //Dm.DmConnectionStringBuilder DmProvider, Version=1.1.0.0, Culture=neutral, PublicKeyToken=7a2d44aa446c6d01
            string name1 = @"Dm.DmConnectionStringBuilder,D:\SelfCode\UtilZ.DotnetDBEx\Test\ConAppCore\bin\Debug\net6.0\DBPlugins\DM\Debug\net6.0\DmProvider.dll";
            string name2 = @"Dm.DmConnectionStringBuilder,D:\SelfCode\UtilZ.DotnetDBEx\Test\ConAppCore\bin\Debug\net6.0\DBPlugins\DM\Debug\net6.0\DmProvider.dll,Version=1.1.0.0, Culture=neutral, PublicKeyToken=7a2d44aa446c6d01";
            string name3 = @"Dm.DmConnectionStringBuilder,D:\SelfCode\UtilZ.DotnetDBEx\Test\ConAppCore\bin\Debug\net6.0\DBPlugins\DM\Debug\net6.0\DmProvider";
            string name4 = @"Dm.DmConnectionStringBuilder,D:\SelfCode\UtilZ.DotnetDBEx\Test\ConAppCore\bin\Debug\net6.0\DBPlugins\DM\Debug\net6.0\DmProvider,Version=1.1.0.0, Culture=neutral, PublicKeyToken=7a2d44aa446c6d01";


            string name5 = @"Dm.DmConnectionStringBuilder,Plugin\DmProvider.dll";
            string name6 = @"Dm.DmConnectionStringBuilder,Plugin\DmProvider.dll,Version=1.1.0.0, Culture=neutral, PublicKeyToken=7a2d44aa446c6d01";
            string name7 = @"Dm.DmConnectionStringBuilder,Plugin\DmProvider";
            string name8 = @"Dm.DmConnectionStringBuilder,Plugin\DmProvider,Version=1.1.0.0, Culture=neutral, PublicKeyToken=7a2d44aa446c6d01";


            string name9 = @"Dm.DmConnectionStringBuilder,Plugin2\*\DmProvider.dll";
            string name10 = @"Dm.DmConnectionStringBuilder,Plugin2\*\DmProvider.dll,Version=1.1.0.0, Culture=neutral, PublicKeyToken=7a2d44aa446c6d01";
            string name11 = @"Dm.DmConnectionStringBuilder,Plugin2\*\DmProvider";
            string name12 = @"Dm.DmConnectionStringBuilder,Plugin2\*\DmProvider,Version=1.1.0.0, Culture=neutral, PublicKeyToken=7a2d44aa446c6d01";

            string name31 = @"Dm.DmConnectionStringBuilder,Plugin2\*\DmProvider,Version=1.1.0.0, Culture=neutral, PublicKeyToken=abcdefg";

            name1 = @"UtilZ.Dotnet.DBSqlServer.SQLServerDBFactory,DBPlugins\SqlServer\*\UtilZ.Dotnet.DBSqlServer";
            TestGetType(name1);
            //TestGetType(name2);
            //TestGetType(name3);
            //TestGetType(name4);

            //TestGetType(name5);
            //TestGetType(name6);
            //TestGetType(name7);
            //TestGetType(name8);

            //TestGetType(name9);
            //TestGetType(name10);
            //TestGetType(name11);
            //TestGetType(name12);

            //TestGetType(name31);
        }

        private static void TestGetType(string assemblyQualifiedName)
        {
            Console.WriteLine("------------------------------------");
            Type type = TypeEx.GetType(assemblyQualifiedName);
            if (type == null)
            {
                Console.WriteLine($"获取类型失败,{assemblyQualifiedName}");
            }
            else
            {
                Console.WriteLine($"获取类型成功{type.FullName},{assemblyQualifiedName}");
            }
        }
    }
}
